package cn.com.dhcc.turbo.web.controller.test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.dhcc.app.core.base.BaseController;
import cn.com.dhcc.app.core.service.Log;
import cn.com.dhcc.app.core.service.Log.LOGTYPE;
import cn.com.dhcc.app.core.util.StrUtil;

@Controller
@RequestMapping("/ztree")
public class ZtreeController extends BaseController {
	Logger logger = Log.getExistLogger(LOGTYPE.SAI);

	@RequestMapping(value = "/nodes")
	@ResponseBody
	public Object nodes(String id,String pId,String tId) {
		System.out.println(">>>>>>>>>>>>>id:" + id);
		System.out.println(">>>>>>>>>>>>>pId:" + pId);
		System.out.println(">>>>>>>>>>>>>tId:" + tId);
		List<Map<String, Object>> nodeList = new ArrayList<Map<String, Object>>();
		try {
			//初始化根节点
			if (StrUtil.isBlank(id)) {
				id = "/";
				Map<String, Object> root = new HashMap<String, Object>();
				root.put("id", id);
				root.put("pId", -1);
				root.put("name", "ZookeeperRoot");
				root.put("isParent", true);
				root.put("open", true);
				nodeList.add(root);
			}

			for (int i = 0; i < 5; i++) {
				Map<String, Object> node = new HashMap<String, Object>();
				String nodeId = id + "_" + i;
				node.put("id", nodeId);
				node.put("pId", id);
				node.put("name", "node" + nodeId);
				nodeList.add(node);
			}
		} catch (Exception e) {
			logger.error("node Error", e);
		}
		return nodeList;
	}
}
